#ifndef __AFXWIN_H__
#define __AFXWIN_H__
#include "_AFXSTAT.H"
#include <process.h>
#include "_AFX.H"
typedef UINT(__cdecl *AFX_THREADPROC)(LPVOID);
class CCmdTarget:public CObject
{
	DECLARE_DYNCREATE(CCmdTarget);
public:
	CCmdTarget();
};

class CWinThread:public CObject
{
	DECLARE_DYNCREATE(CWinThread)
public:
	CWinThread();
	CWinThread(AFX_THREADPROC pfnThreadProc,LPVOID pParam);
	BOOL CreateThread(DWORD dwCreateFlag=0,UINT nStackSize=0,LPSECURITY_ATTRIBUTES lpSecurity=NULL);

	
	HANDLE m_hThread;
	operator HANDLE() const
	{
		return this==NULL?NULL:m_hThread;
	}

	int GetThreadPriority()
	{
		return ::GetThreadPriority(m_hThread);
	}

	BOOL SetThreadPriority(int nPriority)
	{
		return ::SetThreadPriority(m_hThread,nPriority);
	}

public:
	virtual ~CWinThread();
	virtual void Delete();
	void CommonConstruct();
public:	
	DWORD SuspendThread()
	{
		return ::SuspendThread(m_hThread);
	}
	DWORD ResumeThread()
	{
		return ::ResumeThread(m_hThread);
	}

	DWORD m_nThreadID;
	LPVOID m_pThreadParams;
	BOOL m_bAutoDelete;
	AFX_THREADPROC m_pfnThreadProc;

public:
	virtual BOOL InitInstance();
	virtual int Run();
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	virtual BOOL PumpMessage();
	virtual BOOL OnIdle(LONG lCount);
	virtual BOOL IsIdleMessage(MSG* pMsg);
	virtual int ExitInstance();
	MSG m_msgCur;

};

CWinThread* AfxBeginThread(AFX_THREADPROC pfnThreadProc,LPVOID pParam,int nPrority=THREAD_PRIORITY_NORMAL,UINT nStackSize=0,DWORD dwCreateFlags=0,LPSECURITY_ATTRIBUTES lpSecurityAttrs=NULL);
CWinThread* AfxGetThread();
void AfxEndThread(UINT nExitCode,BOOL bDelete = TRUE);

class CWinApp:public CWinThread
{
	DECLARE_DYNCREATE(CWinApp)
public:
	CWinApp();
	virtual ~CWinApp();
	HINSTANCE m_hInstance;
	HINSTANCE m_hPreInstance;
	LPTSTR m_lpCmdLine;
	int m_nCmdShow;
public:
	HCURSOR LoadCursor(UINT nIDResource) const
	{
		return ::LoadCursorA(AfxGetModuleState()->m_hCurrentResourceHandle,(LPCTSTR)nIDResource);
	}
	HICON LoadIcon(UINT nIDResource) const
	{
		return::LoadIcon(AfxGetModuleState()->m_hCurrentResourceHandle,(LPCTSTR)nIDResource);
	}
public:
	virtual BOOL InitApplication();
	virtual BOOL InitInstance();
	virtual int ExitInstance();
	virtual int Run();
};
CWinApp* AfxGetApp();
//{
//	return AfxGetModuleState()->m_pCurrentWinApp;
//}
BOOL AfxWinInit(HINSTANCE hInstance ,HINSTANCE hPreInstance,LPTSTR lpCmdLine,int nCmdShow);

#endif